﻿// lvgl_nvg.cpp: 定义应用程序的入口点。
//
#include <assert.h>
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include "lvgl_nvg.h"
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "lvgl/examples/lv_examples.h"

using namespace std;

lv_display_t *create_window(int32_t w, int32_t h) {
	auto disp = lv_sdl_window_create(w, h);
	assert(disp);

	auto mouse = lv_sdl_mouse_create();
	lv_indev_set_group(mouse, lv_group_get_default());
	lv_indev_set_display(mouse, disp);
	lv_disp_set_default(disp);

	auto mousewheel = lv_sdl_mousewheel_create();
	lv_indev_set_display(mousewheel, disp);

	auto keyboard = lv_sdl_keyboard_create();
	lv_indev_set_display(keyboard, disp);
	lv_indev_set_group(keyboard, lv_group_get_default());

	return disp;
}

void loop(Uint32 interval) {
	while (lv_is_initialized()) {
		auto start = SDL_GetTicks();
		lv_timer_handler();
		auto during = SDL_GetTicks() - start;
		if (interval > during) {
			SDL_Delay(interval - during);
		}
		lv_tick_inc(interval);
	}
}

int main()
{
	lv_init();
	auto disp = create_window(1400, 800);
	lv_demo_benchmark();
	loop(5);
	lv_deinit();
	return 0;
}
